﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Management;

namespace regExport
{
    //Using wmi becuase the servers did not have PeSec.ece on them. 
    class wmi
    {
        //Thee arguments are being pass through the from main method for boths methods in the class wmi.
        //This method is being used in the main program in order to export the file after replacement. 
        static public void ExportReg(string RegKey, string SavePath, string ServerName)
        {
            //The string path is creating a path for the process to run. 
            //The string key is using the parameter RegKey to help create a registry key for the method to use.  
            string path = "\"" + SavePath + "\"";
            string key = "\"" + RegKey + "\"";
            object[] theProcessToRun = { "regedit.exe /e " + path + " " + key + "" };
            ManagementClass mClass = new ManagementClass(@"\\" + ServerName + @"\root\cimv2:Win32_Process");
            mClass.InvokeMethod("Create", theProcessToRun);
        }
        //This method us being used in the main progam in order to import the file before replacement
        static public void ImportReg(string RegKey2, string SavePath2, string ServerName)
        {
            //The string path is creating a path for the process to run. 
            //The string key is using the parameter RegKey to help create a registry key for the method to use.
            string path = "\"" + SavePath2 + "\"";
            string key = "\"" + RegKey2 + "\"";
            object[] theProcessToRun = { "regedit.exe /s " + path + " " + key + "" };
            ManagementClass mClass = new ManagementClass(@"\\" + ServerName + @"\root\cimv2:Win32_Process");
            mClass.InvokeMethod("Create", theProcessToRun);
        }
    }
}
